from apps.MarkManagement.view.common import *
from random import uniform
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sn
import time
import os

class PredictClass(viewsets.ViewSet):
    def title_socre(self, request):
        classId = request.data['classInfo']
        stuId = request.data['studentId']
        points = list(Point.objects.filter(classInfo=classId, student=stuId).values())
        lessonId = list(ClassInfo.objects.filter(id=classId).values())[0]['lesson_id']
        requestedGroups = ['平时', '期中', '期末']
        allowedTitleGroups = list(TitleGroup.objects.filter(name__in=requestedGroups, lesson=lessonId).values())
        allowedIds = []
        for g in allowedTitleGroups:
            t = list(Title.objects.filter(titleGroup=g['id']).values())
            ids = []
            for i in  t:
                ids.append(i['id'])
            allowedIds.extend(ids)

        title_ids = []
        points_number = []
        for point in points:
            if point['title_id'] in allowedIds:
                title_ids.append(point['title_id'])
                points_number.append((point['pointNumber']))

        title_info = list(Title.objects.filter(id__in=title_ids).values())
        title_names = []
        for i in title_info:
            title_names.append(i['name'])

        subjects = {
            'title_names': title_names,
            'points': points_number
        }

        result = {
            'code': 2000,
            'subjects': subjects
        }
        return JsonResponse(result, safe=False)

